#include <stdio.h>

#define INT_MAX (2147483647)
#define INT_MIN (-2148473648)
int aatoii(const char * str)
{
    if(!str) return 0;

    unsigned int result = 0;
    int sign = 1;
    if(*str =='-' || *str == '+')
    {
        if(str[0]=='-')
        {
            sign = -1;
        }
        str++;
    }

    while('0' <= *str && *str <= '9')
    {
        unsigned int digit = *str - '0';
        if((result > INT_MAX/10) || 
        (sign > 0 ? (result == INT_MAX / 10 && digit > INT_MAX %10)
        :(result == ((unsigned int)INT_MAX + 1) / 10 && digit >(((unsigned int)INT_MAX + 1)%10))))
        {
            return sign > 0 ? INT_MAX:INT_MIN;
        }
        result = result*10 + digit;
        str++;
    }

    return ((int)result)*sign;
}

int main()
{
    char str[100] = "+1a68";
    printf("%d\n",aatoii(str));
    return 0;
}